package controller;

import Utils.ConstantUtils;
import Utils.ResponseData;
import com.baomidou.dynamic.datasource.annotation.DS;
import entity.SysAccounts;
import entity.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import service.UserInfoService;
import vo.SysAccountsVo;
import vo.SysPermissionVo;


import javax.annotation.Resource;

/**
 * (UserInfo)表控制层
 *
 * @author liujh
 * @since 2020-06-28 17:38:21
 */
@Controller
@RequestMapping(value = "user",produces = "application/json;utf-8")
@Slf4j
public class UserInfoController {
    /**
     * 服务对象
     */
    @Resource
    private UserInfoService userInfoService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    @ResponseBody
    public UserInfo selectOne(Long id) {
        return this.userInfoService.queryById(id);
    }



    @GetMapping("selectOne2")
    @ResponseBody
    @DS("db2")
    public UserInfo selectOne2(Long id) {
        return this.userInfoService.queryById(id);
    }


    @GetMapping("msg")
    public String test(Model m){
      // UserInfo user =  this.userInfoService.queryById((long)30261);
       UserInfo user = new UserInfo();
       user.setUsername("admin");
       user.setId((long)101);
       m.addAttribute("user",user);
       log.info("user:{}",user.getUsername());
       return "users/userInfo";
    }

    @GetMapping("addRedis")
    @ResponseBody
    public ResponseData TestRedisAdd(){
        log.info("init mehtod:{}");
       return userInfoService.testRedisAdd();
    }


    @GetMapping("logs")
    @ResponseBody
    public ResponseData teseLogOut(){
        log.trace("*****************trace**********");
        log.debug("*************debug*************");
        log.info("**************info****************");
        log.warn("****************warn***************");
        log.error("****************error*************");
        return ResponseData.success(200,"ok");
    }

    @PostMapping("add")
    public ResponseData save(@RequestBody UserInfo userInfo){
        userInfoService.insert(userInfo);
        return ResponseData.success(200,"ok");
    }


}